<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改劳动合同')" />
    <th:block th:include="include :: datetimepicker-css" />
    <link th:href="@{/ajax/libs/layui/css/layui.css}" rel="stylesheet"/>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-contract-edit" th:object="${hrContract}">
            <input name="id" th:field="*{id}" type="hidden">


            <div class="form-group">
                <label class="col-sm-3 control-label ">员工：</label>
                <div class="col-sm-8">
                    <input name="empName" th:field="*{empName}" class="form-control" type="text" readonly>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label ">合同主体：</label>
                <div class="col-sm-8">
                    <input name="subjectContract" th:field="*{subjectContract}"  maxlength="20" class="form-control" type="text" >
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">合同年限：</label>
                <div class="col-sm-8">
                    <input name="contractYear" th:field="*{contractYear}" class="form-control" type="number" maxlength="2" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">合同开始：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="contractStar" onchange="$.common.getTimeYeas('contractStar','contractEnd','contractYear')"  th:value="${#dates.format(hrContract.contractStar, 'yyyy-MM-dd')}"  readonly="readonly"  class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">合同结束：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="contractEnd" onchange="$.common.getTimeYeas('contractStar','contractEnd','contractYear')"  th:value="${#dates.format(hrContract.contractEnd, 'yyyy-MM-dd')}"  readonly="readonly"  class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">封面：</label>
                <div class="col-sm-8">
                    <input name="contractUrl" id="contractUrl" th:field="*{contractUrl}" class="form-control" type="hidden" required>
                    <div class="layui-upload">
                        <button type="button" class="layui-btn" id="test1">上传图片</button>
                        <div class="layui-upload-list">
                            <img class="layui-upload-img" id="demo1">
                            <p id="demoText"></p>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:src="@{/ajax/libs/layui/layui.all.js}"></script>
    <script type="text/javascript">
        var prefix = ctx + "hr/contract";
        $('#demo1').attr('src', '[[${hrContract.contractUrl}]]'); //图片链接（base64）
        $("#form-contract-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.common.isEmpty($('#contractUrl').val())){
                $.modal.alertWarning("请输上传封面图片。");
                return;
            }
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-contract-edit').serialize());
            }
        }

        $("input[name='contractStar']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='contractEnd']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        layui.use('upload', function(){
            var $ = layui.jquery
                ,upload = layui.upload;

            //普通图片上传
            var uploadInst = upload.render({
                elem: '#test1'
                ,url: ctx + "common/upload" //改成您自己的上传接口
                ,before: function(obj){
                    //预读本地文件示例，不支持ie8
                    obj.preview(function(index, file, result){

                        $('#demo1').attr('src', result); //图片链接（base64）
                    });
                }
                ,done: function(res){
                    //如果上传失败
                    if(res.code > 0){
                        return layer.msg('上传失败');
                    }
                    //上传成功
                    $('#contractUrl').val(res.fileName); //图片路径
                }
                ,error: function(){
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function(){
                        uploadInst.upload();
                    });
                }
            });
        });


    </script>
</body>
</html>